package jvm.jtacck.db.records;

/**
 * 
 * @author Chris Gamble
 * 
 *         Represents a type of user of the system. each user belongs to one of
 *         these types, and depending on the type of user, they are restricted
 *         to what they can access.
 * 
 */
public class UserType extends Record {

    private static final long serialVersionUID = -8832343003300183498L;
    public final int type_id;
    public final String name;
    public final String description;

    /**
     * Constructs a new UserType
     * 
     * @param id
     *            the unique id of the UserType
     *            NON-NULLABLE
     * @param name
     *            the name of the UserType
     * @param description
     *            an english description of what this type of user can do
     */
    public UserType(int id, String name, String description) {
        this.type_id = id;
        this.name = name;
        this.description = description;
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof UserType) {
            UserType other = (UserType) o;
            boolean x = 
                    (type_id == other.type_id) &&
                    checkString(name, other.name) &&
                    checkString(description, other.description);
            return x;
        }
        return false;
    }

    public boolean checkString(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        }else {
            return s1.equals(s2);
        }
    }
    
    @Override
    public int hashCode() {
        return type_id + name.hashCode() + 
        description.hashCode();
    }

    public String toString() {
        return type_id + ": " + name + ", " + description + ".";
    }
}
